package com.example.onlinemusic.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Description:添加系统配置拦截器!
 * User: hold on
 * Date: 2022-07-27
 * Time: 12:29
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {
    //将BCrypetPasswordEncoder对象交给spring管理!
    @Bean
    public BCryptPasswordEncoder getBCryptPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }

    //添加拦截器!
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        LoginInterceptor loginInterceptor = new LoginInterceptor();
        registry.addInterceptor(loginInterceptor)
                //拦截该项目目录下的所有文件!
                .addPathPatterns("/**")
                //排除无关文件
                .excludePathPatterns("/js/**.js")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/css/**.css")
                .excludePathPatterns("/fronts/**")
                .excludePathPatterns("/player/**")
                //排除登入注册接口!
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/reg.html")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/clover.html");
    }
}
